package com.kanas.webak.config.domain;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;

import com.kanas.framework.support.AbstractModel;
import com.kanas.framework.util.StringUtils;

@Entity
@Table(name="kanas_data_dict_type")
@JsonIgnoreProperties({"dictValue"})
public class DictType extends AbstractModel {

	@Transient
	private static final long serialVersionUID = 1L;

	@Id
	@Column(name="id", length=32)
	private String id;
	@Column(name="type_code", length=100)
	private String typeCode;
	@Column(name="label", length=100)
	private String label;
	@OneToMany(mappedBy = "dictType", cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH}, fetch = FetchType.LAZY)
	private Set<DictValue> dictValue;
	
	@Transient
	private String oldId;
	@Transient
	private String parentId;
	
	public DictType() {
		this.id = StringUtils.generateUUID();
	}
	
	public DictType(String code, String label) {
		this.id = StringUtils.generateUUID();
		this.typeCode = code;
		this.label = label;
	}
	
	@Override
	public String toIdString() {
		return id;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getTypeCode() {
		return typeCode;
	}

	public void setTypeCode(String typeCode) {
		this.typeCode = typeCode;
	}

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}


	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	public String getOldId() {
		return oldId;
	}

	public void setOldId(String oldId) {
		this.oldId = oldId;
	}

	public Set<DictValue> getDictValue() {
		if(dictValue == null) dictValue = new HashSet<DictValue>();
		return dictValue;
	}

	public void setDictValue(Set<DictValue> dictValue) {
		this.dictValue = dictValue;
	}
	
}
